﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Data;
using ESOL.Common.Entity;

namespace ESOL.Services
{
    [ServiceContract]
    public interface IProdService
    {
        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //DataSet GetUiPoByCondition(int pageIndex, int pageCount, string condition);

        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //bool UpdatePo(ProdPoEntity po);

        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //bool SplitPo(ProdPoEntity curPo, ProdPoEntity splitPo);

        #region 生产计划
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdMaintainPo AddMaintainPo(ProdMaintainPo mp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdMaintainPo UpdateMaintainPo(ProdMaintainPo mp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelMaintainPo(ProdMaintainPo mp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdMaintainPo GetMaintainPoByKey(string PoId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdMaintainPo GetMaintainPoByCondition(ProdPlanOrderEntity PoCondition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdMaintainPo> GetMaintainPoAllByCondition(ProdPoQueryCondition con);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTODataTable GetMtrlReqPo();
        /// <summary>
        /// 根据生产计划，生成工单、采购单、工单任务
        /// </summary>
        /// <param name="bomItems"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? ProdPoToWo(string userNo, ProdMaintainPo po, DataSet bomItems);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdMaintainWo> CreateWoFromPo(string userNo, ProdMaintainPo mpo);
        #endregion


        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //int? AddPoTaskuser(ProdPoTaskuserEntity tu);

        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //int? UpdatePoTaskuser(ProdPoTaskuserEntity tu);

        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //int? DelPoTaskuser(ProdPoTaskuserEntity tu);

        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //List<ProdPoTaskuserEntity> GetPoTaskuserAllList(string poId, string bomItemId, string bomTechnicItemId);

        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //int? SavePoTaskuser(ProdPoTaskuserEntity tu);

        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //int? SavePoTaskusers(List<ProdPoTaskuserEntity> tus);9

        #region 生产计划
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string WorkPlanWfEnd(ProdMaintainPo po);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string WorkPlanWfStart(ProdMaintainPo po);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdPlanOrderEntity> GetUpdateScheduleRelationPoList(string poId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetNotFinishPoAndWos();


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTODataTable GetProductionReqQty(string poNo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTODataTable GetProductionSalesBalanceQuery();
        #endregion



        #region 工单
        /// <summary>根据ID，查询工单
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdWoEntity GetProdWoByKey(string id);

        /// <summary>根据ID，查询工单
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdMaintainWo GetProdMaintainWoByKey(string id);

        /// <summary>根据条件，查询工单
        /// 
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoAllDsByCondition(ProdWoQueryCondition condition);



        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdMaintainWo> CreateWo(string userNo, string productId, string bomId, decimal planQty);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool SaveWoList(List<ProdMaintainWo> woList);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool UpdateWoList(List<ProdMaintainWo> woList);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdMaintainWo> GetProdWoByPoId(string planOrderId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdWoEntity GetProdWoByWoNo(string WoNo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool UpdateProdWo(ProdWoEntity wo);
        #endregion

        #region 工单用料

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdWoMtrlEntity> GetProdWoMtrlByPoNo(string PoNo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdWoMtrlEntity> GetProdWoMtrlByWoNo(string woNo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoMtrlDsByWoNo(string woNo);
        #endregion

        #region 杂项

        /// <summary>
        /// 根据用户，查询执行中的工单任务
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoTaskAllDsByUserNo(string userNo);

        /// <summary>
        /// 根据工单，查询非删除状态工单任务
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoTaskAllDsByWoId(string woId);

        /// <summary>
        /// 根据用户，查询非删除状态工单任务
        /// </summary>
        /// <param name="userNo"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoProcessingTaskAllDsByUserNo(string userNo);

        /// <summary>
        /// 查询草稿状态且工序为放料的工单任务
        /// </summary>
        /// <returns>wt.*,wo.WO_NO,po.CONTRACT_MODEL,mp.PRODUCT_CODE,mp.PRODUCT_NAME,pt.TECHNIC_NAME,
        ///ma.PRODUCT_NAME,bim.PICKING_MODEL,bim.NET_SIZE,bim.GROSS_SIZE,bim.UNIT_WEIGHT</returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoMaterialTaskAllDs();

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoMaterialTaskAllDsByCondition(ProdWoTaskCondition con);

        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //ProdMaintainWoPick SaveProdWoPick(ProdMaintainWoPick woPick,List<ProdMaintainPickItem>);

        /// <summary>
        /// 根据工单任务，创建放料单
        /// </summary>
        /// <param name="ds">wt.*,wo.WO_NO,po.CONTRACT_MODEL,mp.PRODUCT_CODE,mp.PRODUCT_NAME,pt.TECHNIC_NAME,
        ///ma.PRODUCT_NAME,bim.PICKING_MODEL,bim.NET_SIZE,bim.GROSS_SIZE,bim.UNIT_WEIGHT</param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdWoPickEntity CreateProdWoPick(string userNo, DataSet ds);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoPickAllDsByCondition(ProdWoPickQueryCondition con);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoPickItemAllDsByPickId(string pickId);

        /// <summary>
        /// 工单任务放料，保存放料数据
        /// 库存扣除数量
        /// 放料单状态变为“完成”,工单任务状态变为“完成”
        /// </summary>
        /// <param name="pick"></param>
        /// <param name="pickItems"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? Pick(ProdWoPickEntity pick, List<ProdWoPickitemEntity> pickItems);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? AddTechnic(ProdTechnicEntity technic);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? UpdateTechnic(ProdTechnicEntity technic);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelTechnic(ProdTechnicEntity technic);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdTechnicEntity GetTechnicByKey(string id);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="queryCondition"></param>
        /// <returns>t.*,u1.firstName as CREATED_USER,u2.firstName as UPDATED_USER </returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetTechnicAllDsByCondition(ProdTechnicQueryCondition queryCondition);

        /// <summary>
        /// 报工
        /// 新增报工记录
        /// 更新工作任务表
        /// 下一任务状态改为“处理中”
        /// </summary>
        /// <param name="rw"></param>
        /// <returns></returns>
        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //int? ReportWork(ProdRwEntity rw);

        /// <summary>
        /// 根据工单任务，查询需要领料的物料
        /// </summary>
        /// <param name="woTask"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdMaintainPickItem> GetPickItemAllListByWoTask(ProdWoTaskEntity woTask);

        /// <summary>
        /// 根据工单任务和领料，创建出库申请单
        /// 启动工作流
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        InvOappEntity CreatedInvOappByWoTask(string userNo, ProdWoTaskEntity wt, List<ProdMaintainPickItem> pickItems);

        #endregion


        #region 可报工数据
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetWoAllowRptWorkQtyDsBySql(ProdWoTaskCondition condition);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetWoAllowRptWorkQtyDsByWorkGroup(ProdWoTaskCondition condition);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdWipCurEntity> GetProdWipCurByCondition(ProdWipCurEntity conidtion);

        //线上物料的可用量
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdWipMtrlCurEntity> GetProdWipMtrlCurByCondition(ProdWipMtrlCurEntity conidtion);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWipMtrlCurDsByCondition(ProdWipMtrlCurEntity conidtion);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string ReportWork(ProdWipCurEntity wip, ProdWipHisEntity his);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetWipProc(ProdWoQueryCondition condition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetWip(ProdWoQueryCondition condition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetWipHisProcs(ProdWoTaskCondition condition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetWipKPI(ProdWoTaskCondition condition);

        //入帐
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string WipLogon(ProdWipCurEntity wip, ProdWipHisEntity his);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetWoAllowLogonQtyDsBySql(ProdWoTaskCondition condition);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetFinishedWip(string woNo);

        //产品下线
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string WipOffLine(DataSet offlineWips);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string WipInventory(DataSet offlineWips);

        #endregion


        #region 工作组
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdWorkgroupEntity> GetWorkGroupByCondition(ProdWorkgroupEntity conidtion);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ProdWorkgroupEntity GetWorkGroupByKey(string workGroupId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string AddProdWorkGroup(ProdWorkgroupEntity workgroupEntity, List<ProdWorkgroupUserEntity> workgroupUsers);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string UpdateProdWorkGroup(ProdWorkgroupEntity workgroupEntity, List<ProdWorkgroupUserEntity> workgroupUsers);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string DeleteProdWorkGroup(ProdWorkgroupEntity workgroupEntity);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdWorkgroupUserEntity> GetWorkGroupUsersByWorkGroupId(string workgroupId);
        #endregion


        #region 生产排程
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string ScheduleWo(ProdWoEntity wo, List<ScheduleInput> input, string SchType, List<string> waitingWoList);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoTask(string woNo);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoTaskDsByPo(string poId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWoTaskDailyByWorkGroup(DateTime date);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetAllWorkGroupFromWoTask(DateTime date);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetScheduleDetail(string woNo, string workgroup, string technicId);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdWoEntity> GetScheduleWoPriority(string planOrderId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ScheduleInput> GetScheduleWoInputFormat(string woNo);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string UpdateWoScheduleDate(List<string> woList);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string SaveWoTask(List<string> woList);
        #endregion


        #region 委外加工
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string UpdateCooperationOrder(ProdCooperationOrderEntity entity);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string AddCooperationOrder(ProdCooperationOrderEntity entity);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string DeleteCooperationOrder(ProdCooperationOrderEntity entity);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<ProdCooperationOrderEntity> GetCooperationOrderList(ProdCooperationOrderEntity entity);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdCooperationOrderDsByCondition(ProdCooperationOrderEntity entity);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string UpdateCooperationOrderList(List<ProdCooperationOrderEntity> entityList);
        #endregion

        #region 生产相关查询

        //生产日报表
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetWorkDaily(DateTime date);
        #endregion



        #region 生产维修

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetProdWipMtrlHisDsByCondition(ProdWipMtrlHisEntity condition);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetAllowedRepairQty(ProdWipCurEntity condition);


        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string ProdRepairWork(ProdWipCurEntity wip, ProdWipHisEntity his, DataTable DisAssembleMtrls, DataTable AssembleMtrls);




        #endregion

        #region 质检
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string QCReportWork(ProdWipCurEntity wip, ProdWipHisEntity his, Common.DTO.IpqcSaveParam param);
        #endregion

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool TestConnect();

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTODataTable GetMtrlHoldByPo();
    }
}
